package user_assets_ewallet

import (
	"context"
	"strconv"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/jinzhu/copier"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserEWalletInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 用户电子钱包信息 - 查询
func NewUserEWalletInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserEWalletInfoLogic {
	return &UserEWalletInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserEWalletInfoLogic) UserEWalletInfo(req *types.UserEWalletsInfoRequest) (resp *types.UserEWalletsInfoResponse, err error) {
	info, err := l.svcCtx.AssetsRpc.UserChannel.UserEWalletsInfo(l.ctx, &rpc.UserEWalletsRequest{
		UserId:     req.UserID,
		Account:    req.Account,
		WalletName: strconv.FormatInt(int64(req.WalletName), 10),
		Username:   req.Username,
	})
	var dataList []*types.UserEWalletsInfo

	if err != nil {
		return &types.UserEWalletsInfoResponse{
			UserEWalletsInfoList: dataList,
		}, err
	}
	_ = copier.Copy(&dataList, info.UserEWalletsInfoList)

	return &types.UserEWalletsInfoResponse{
		UserEWalletsInfoList: dataList,
	}, nil
}
